/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wmauswertung;

/**
 *
 * @author mcnanuschi
 */
public class Match {

    private String guest, home, score;
    private int guestScore, homeScore, lock = 0;

    /**
     * default constructor to create a match
     * @param guest
     * @param home
     */
    public Match(String home, String guest) {
        this.guest = guest;
        this.home = home;
        this.guestScore = 0;
        this.homeScore = 0;
    }

    /**
     * function to set to match score by corrections.
     * to set a score during game use function "scoreFor(String team)"
     * @param home
     * @param guest
     */
    public void setScore(int home, int guest) {
        if (lock == 0) {
            this.guestScore = guest;
            this.homeScore = home;
        } else {
            System.out.println("Game allready closed. Unable to change score afterwards\n");
        }
        goal();
    }

    /**
     * function to increase score for one of the two teams
     * @param String team (must be "guest" or "home")
     */
    public void scoreFor(String team) {
        if (lock == 0) {
            if (team.equals("guest")) {
                this.guestScore++;
            }
            if (team.equals("home")) {
                this.homeScore++;
            }
            goal();
        } else {
            System.out.println("Wrong Parameter or game allready closed! Score leaves untouched!\n");
        }
    }

    /**
     * prints out a human understandable string for match score
     * @return humanReadableScore
     */
    public String printScore() {
        score = home + " " + Integer.toString(homeScore) + ":" + Integer.toString(guestScore) + " " + guest;
        return score;
    }

    /**
     * returns the score of the match as String e.g. "1:2"
     * @return score e.g. "1:2"
     */
    public String getScore() {
        score = Integer.toString(homeScore) + ":" + Integer.toString(guestScore);
        return score;
    }

    /**
     * returns the guests score as integer
     * @return guestScore
     */
    public int getGuestScore() {
        return guestScore;
    }

    /**
     * returns the homes score as integer
     * @return homeScore
     */
    public int getHomeScore() {
        return homeScore;
    }

    /**
     * Function to lock/close a game. Afterwards its unable to change score any more
     */
    public void closeGame() {
        this.lock++;
        System.out.println("Match is closed! Final Score is "+this.printScore());
    }

    /**
     * function to notify a change in the match
     */
    private void goal() {
        System.out.println("GOOOOOAAAALLL!!!! New Score is: " + this.printScore());
    }
}
